package com.vhall.component.plugin.core.service.listener;

import com.vhall.component.plugin.core.service.PaasService;
import com.vhall.component.plugin.core.service.event.PaasMessageEvent;
import com.vhall.component.plugin.core.service.event.PaasMessageReqDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

/**
 * PAAS消息事件监听
 *
 * @author yuanzh
 * @date 2021/9/14
 */
@Service
@Slf4j
@EnableAsync
public class PaasMessageEventListener implements ApplicationListener<PaasMessageEvent> {

    @Autowired
    private PaasService paasService;

    /**
     * PAAS异步消息发送
     *
     * @param event 事件对象
     */
    @Async
    @Override
    public void onApplicationEvent(PaasMessageEvent event) {
        PaasMessageReqDTO paasMessageReq = event.getPaasMessageReq();
        paasService.sendMessage(paasMessageReq);
        log.info("消息事件处理完成：messageReq: {}", paasMessageReq);
    }
}
